#!/usr/bin/env bash
#########################################################################
# File Name   : copy_to_win10.sh
# Author      : seadog
# mail        : seadog0514@163.com
# Version     : 0.1
# Created Time: Sat 2024-03-30 21:59:54(+0800)
#########################################################################

# Usage:

set -euo pipefail
# set -E
#     If set, any trap on ERR is inherited by shell functions, command
#     substitutions, and commands executed in a subshell environment.

# !!! basic utils
{
  export TZ="Asia/Shanghai"
  APP_ROOT=$(dirname "$(readlink -fm "$0")")
  cd "${APP_ROOT}"
  function usage() {
    echo """

    """
  }

  function logme() {
    local LOGTYPE=$1
    shift
    local MSGC=$*
    local LOGTIME
    LOGTIME="$(date '+%Y-%m-%d %H:%M:%S')"
    case $LOGTYPE in
      INFO | i) echo -e "$LOGTIME => INFO  ¦ ${MSGC}" ;;
      WARN | w) echo -e "\e[0;33m$LOGTIME => WARN  ¦ ${MSGC}\e[00m" ;;
      DEBUG | d) echo -e "\e[0;96m$LOGTIME => DEBUG ¦ ${MSGC}\e[00m" >&2 ;;
      ERR | e)
        echo -e "\e[0;31m$LOGTIME => ERROR ¦ ${MSGC}\e[00m"
        return 1
        ;;
    esac
  }
}

if ! mount | grep -q win10_10_share; then
  logme e "win10_10_share not mounted"
fi

mkdir /home/share_samba/win10_10_share/tma 2>/dev/null || true
rm -rf /home/share_samba/win10_10_share/tma/* || true
cp -r * /home/share_samba/win10_10_share/tma/

(
  cd /home/share_samba/win10_10_share/tma/utils/
  for i in *.py; do
    echo $i
    sed -i 's/from tma\./from /' "$i"
  done
  sed -i 's/from tma\./from /' ../dw.py
  mkdir ../.git
)
